package it.xiuxian.homepage.activity

import android.view.KeyEvent
import android.view.View
import android.webkit.WebChromeClient
import android.webkit.WebViewClient
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.zzhoujay.richtext.RichText
import it.xiuxian.homepage.R
import it.xiuxian.homepage.databinding.HomepageBannerdetailBinding
import it.xiuxian.homepage.presenter.BannerDetailActivityPresenter
import it.xiuxian.lib.base.ArouterAddress
import it.xiuxian.lib.base.BaseActivity
import it.xiuxian.lib.http.HttpConfig


@Route(path = ArouterAddress.BANNERDETAILACTIVITY)
class BannerDetailActivity:BaseActivity<BannerDetailActivityPresenter>() {
    @JvmField
    @Autowired
    var flag:String?=null
    @JvmField
    @Autowired
    var content:String?=null
    override val layoutId: Int
        get() = R.layout.homepage_bannerdetail
    override val presenter: BannerDetailActivityPresenter
        get() = BannerDetailActivityPresenter()

    override fun initView() {
        //super.initView()
        ARouter.getInstance().inject(this)
        setTitle("详情")
      var binding =  getViewDataBinding<HomepageBannerdetailBinding>()
        if(flag=="2"){
            RichText.from(content).into(binding.tv)
            binding.web.visibility = View.GONE
            binding.tv.visibility  = View.VISIBLE
        }else{
            binding.web.visibility = View.VISIBLE
            binding.tv.visibility  = View.GONE
            //            webView.setBackgroundColor(0);
//            webView.getBackground().setAlpha(0);
            binding.web.getSettings().setJavaScriptEnabled(true)
            binding.web.setWebChromeClient(WebChromeClient())
            binding.web.setWebViewClient(WebViewClient())
            binding.web.loadUrl(content!!)
            binding.web.setOnKeyListener { v, keyCode, event ->
                if (event.getAction() === KeyEvent.ACTION_DOWN) {
                    if (keyCode === KeyEvent.KEYCODE_BACK && binding.web.canGoBack()) {
                        binding.web.goBack()
                        return@setOnKeyListener true
                    }
                }
                false
            }
        }

    }
}